<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script>
    // 10. 编写函数maxr(char) 返回字符串char中最长的连续重复字母,比如maxr("mmmiijjjjkkkkkkssptr") 返回"kkkkkk"
    function maxr(char) {
    // i和j分别指向字符串的0和1位,依次检测相邻的两个字符串
		// 定义两个位置淘汰重复次数短的，龟兔赛跑，长的那个输出
		var i = 0;
		var j = 1;
		var len = 0;
		var str = "";
		while(i < char.length) {
			if(char.charAt(i) == char.charAt(j)) {
				j++;
			} else {
				if(j - i > len) {
					len = j - i;
					str  = char.charAt(i);
				}
				i = j;
				j++;
			}
		}
		return str;
	}
  console.log(maxr('mmmiijjjjkkkkkssptr'));
  </script>)
</head>
<body>
  
</body>
</html>